package fusion.gui;



import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.JFrame;

import deformation.Deformation;
import fusion.LinearCombination;

public class FusionFrame extends JFrame {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private LinearCombination fusion;
	/**
	 * @return the fusion
	 */
	public LinearCombination getFusion() {
		return fusion;
	}

	/**
	 * @param fusion the fusion to set
	 */
	public void setFusion(LinearCombination fusion) {
		this.fusion = fusion;
		Rectangle r = fusion.getDeformationPainter1().getBounds().union(fusion.getDeformationPainter2().getBounds());
		this.setSize(r.getSize());
		this.repaint();
	}
	
	public void resize(){
		Rectangle r = fusion.getDeformationPainter1().getBounds().union(fusion.getDeformationPainter2().getBounds());
		this.setSize(r.getSize());
		this.repaint();
	}

	private double factor = 0.5;
	private double color_factor = 0.5;
	public FusionFrame(LinearCombination fusion){
		super("Fusion");
		this.setFusion(fusion);
		this.setVisible(true);
	}
	
	@Override
	public void paint(Graphics g) {
		Rectangle r = fusion.getDeformationPainter1().getBounds().union(fusion.getDeformationPainter2().getBounds());
		Image image = fusion.getfuseImage(factor,color_factor ,r);
		g.drawImage(image, r.x, r.y, null);
	}

	public double getFactor() {
		return factor;
	}

	public void setFactor(double factor) {
		if (factor<=1 && factor >=0) {
			this.factor = factor;
			this.repaint();
		}
		
	}

	public void setFactor(double factor, double color_factor) {
		if (factor<=1 && factor >=0) {
			this.factor = factor;
		}
		if (color_factor<=1 && color_factor >=0) {
			this.color_factor  = color_factor;
		}
		this.repaint();
		
	}


}
